package cn.kgc.controller;

import cn.kgc.dao.Fc_ResumeDao;
import cn.kgc.pojo.Resume;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.security.auth.login.Configuration;
import java.util.List;

/**
 * @program:hrsystem
 * @description:
 * @author:冯聪聪
 * @create:2022-02-08 18:16
 */
@Controller
@RequestMapping("/fc")
public class Fc_Controller {
    /**
     *   注入dao层
     */
    @Resource
    private Fc_ResumeDao dao;

    /**
     *   跳转到面试管理页面
     */
    @RequestMapping("/mianshi")
    public String mianshi() {
        return "fcyemian/mianShiGuanLi.html";
    }

    /**
     *   跳转到系统首页
     */
    @RequestMapping("/shujugailan")
    public String shujugailan() {
        return "fcyemian/main";
    }

    /**
     *   分页查询(面试管理)
     */
    @ResponseBody
    @RequestMapping("/mianshiguanli")
    public String mianshi(@RequestParam Integer pageSize,
                          @RequestParam Integer currentPage,
                          @RequestParam String reName1,
                          @RequestParam String posName,
                          @RequestParam String workEx,
                          @RequestParam String resState,
                          @RequestParam String recommendTime) {
        PageHelper.startPage(currentPage, pageSize);
        Page<Resume> userList = dao.selAllResume(reName1, posName, workEx, resState, recommendTime);
        userList.forEach(System.out::println);
        PageInfo<Resume> pageInfo = new PageInfo<Resume>(userList);
        return JSON.toJSONStringWithDateFormat(pageInfo, "yyyy-MM-dd");
    }

    /**
     *    跳转到面试结果登记页面
     */
    @RequestMapping("/mianshidengji/{id}")
    public String dengji(@PathVariable Integer id, Model model) {
        List<Resume> resumes = dao.selResumeById(id);
        model.addAttribute("resumeList", resumes);
        return "fcyemian/mianShiJieGuoDengJi";
    }


    /**
     *    跳转到简历回收站页面
     */
    @RequestMapping("/jianlihuishouzhan")
    public String jianlihuishouzhan() {
        return "fcyemian/jianLiHuiShouZhan";
    }

    /**
     * 简历回收站页面分页查询
     */
    @ResponseBody
    @RequestMapping("/huishouzhanchaxun")
    public String huishouzhanchaxun(@RequestParam Integer pageSize,
                          @RequestParam Integer currentPage,
                          @RequestParam String reName1,
                          @RequestParam String posName,
                          @RequestParam String workEx,
                          @RequestParam String recommendTime) {

        PageHelper.startPage(currentPage, pageSize);
        Page<Resume> userList = dao.selAllDel(reName1, posName, workEx,recommendTime);
        userList.forEach(System.out::println);
        PageInfo<Resume> pageInfo = new PageInfo<Resume>(userList);
        return JSON.toJSONStringWithDateFormat(pageInfo, "yyyy-MM-dd");
    }

    /**
     * 简历回收站 简历恢复
     */
    @ResponseBody
    @RequestMapping("/jianlihuifu")
    public boolean jianlihuifu(@RequestParam Integer id) {
        int i = dao.recoverResState(id);
        boolean b = false;
        if(i>0){
            b=true;
        }
        return b;
    }

    /**
     * 简历回收站 彻底删除
     */
    @ResponseBody
    @RequestMapping("/jianlidel")
    public boolean jianlidel(@RequestParam Integer id) {
        int i = dao.delById(id);
        boolean b = false;
        if(i>0){
            b=true;
        }
        return b;
    }


    /**
     * 跳转到录用管理页面
     */
    @RequestMapping("/luyong")
    public String luyong() {
        return "fcyemian/luYongGuanLi";
    }

    /**
     * 录用管理页面分页查询
     */
    @ResponseBody
    @RequestMapping("/luyongguanli")
    public String luyongguanli(@RequestParam Integer pageSize,
                               @RequestParam Integer currentPage,
                               @RequestParam String reName1,
                               @RequestParam String posName,
                               @RequestParam String workEx,
                               @RequestParam String recommendTime) {

        PageHelper.startPage(currentPage, pageSize);
        Page<Resume> userList = dao.selAllResumeForLuYong(reName1, posName, workEx,recommendTime);
        userList.forEach(System.out::println);
        PageInfo<Resume> pageInfo = new PageInfo<Resume>(userList);

        return JSON.toJSONStringWithDateFormat(pageInfo, "yyyy-MM-dd");
    }

    /**
     * 跳转到录用结果登记页面
     */
    @RequestMapping("/luyongdengji/{id}")
    public String luyongdengji(@PathVariable Integer id,
                               Model model) {
        List<Resume> resumes = dao.selResumeById(id);
        model.addAttribute("resumeList",resumes);
        return "fcyemian/luYongJieGuoDengJi";
    }


    /**
     * 跳转到面试明细页面（携带数据）
     */
    @RequestMapping("/mingxi/{id}")
    public String selById(@PathVariable Integer id, Model model) {

        List<Resume> resumes = dao.selResumeById(id);
        model.addAttribute("resumeList", resumes);
        return "fcyemian/mianShiMingXi";
    }

    /**
     * 跳转到录用明细页面（携带数据）
     */
    @RequestMapping("/luyongmingxi/{id}")
    public String luyongmingxi(@PathVariable Integer id, Model model) {

        List<Resume> resumes = dao.selResumeById(id);
        model.addAttribute("resumeList", resumes);
        return "fcyemian/luYongMingXi";
    }


    /**
     * 面试结果登记方法一
     */
    @ResponseBody
    @RequestMapping("/addmianshijieguo01")
    public Boolean addmianshijieguo01(@RequestParam Integer id,
                                      @RequestParam String resState,
                                      @RequestParam String firstMianPeople,
                                      @RequestParam String firstMianAppraise) {

        boolean b = false;
        int i = dao.addMianShiResult01(id, resState, firstMianPeople, firstMianAppraise);
        if (i > 0) {
            b = true;
        }
        return b;
    }

    /**
     * 面试结果登记方法二
     */
    @ResponseBody
    @RequestMapping("/addmianshijieguo02")
    public Boolean addmianshijieguo02(@RequestParam Integer id,
                                      @RequestParam String resState,
                                      @RequestParam String secondMianPeople,
                                      @RequestParam String secondMianAppraise){
        boolean b = false;
        int i = dao.addMianShiResult02(id, resState, secondMianPeople, secondMianAppraise);
        if (i > 0) {
            b = true;
        }
        return b;
    }

    /**
     * 面试结果登记方法三
     */
    @ResponseBody
    @RequestMapping("/addmianshijieguo03")
    public Boolean addmianshijieguo03(@RequestParam Integer id,
                                      @RequestParam String resState,
                                      @RequestParam String thirdMianPeople,
                                      @RequestParam String thirdMianAppraise){
        boolean b = false;
        int i = dao.addMianShiResult03(id, resState, thirdMianPeople, thirdMianAppraise);
        if (i > 0) {
            b = true;
        }
        return b;
    }


    /**
     * 两个页面共用的删除
     */
    @ResponseBody
    @RequestMapping("/del1")
    public Boolean addmianshijieguo03(@RequestParam Integer id,
                                      @RequestParam String resState) {
        boolean b = false;
        int i = dao.updResState(id, resState);

        if (i > 0) {
            b = true;
        }
        return b;
    }

    /**
     * 录用管理页面设置录用决议
     */
    @ResponseBody
    @RequestMapping("/updluyongjueyi")
    public Boolean updluyongjueyi(@RequestParam Integer id,
                                  @RequestParam String resState,
                                  @RequestParam String luYongJueYi) {
        boolean b = false;
        int i = dao.updluyongjueyi(id,resState,luYongJueYi);
        if (i > 0) {
            b = true;
        }
        return b;
    }

    /**
     * 数据分析页面饼图1(简历状态及个数)
     */
    @ResponseBody
    @RequestMapping("/bingtuhuidiao")
    public String bingtuhuidiao() {
        List<Resume> list = dao.selCountForResState();
        return JSON.toJSONString(list);
    }

    /**
     * 数据分析页面饼图1(学历水平及人数)
     */
    @ResponseBody
    @RequestMapping("/bingtuhuidiao2")
    public String bingtuhuidiao2() {
        List<Resume> list = dao.selCountForEducation();
        return JSON.toJSONString(list);
    }
}
